<?php
	/* Functions in this file */
	/**************************/

	// GetBeatsPerMinute()
	// GetBeatType()
	// GetDescription()
	// GetListessoBeatType()
	// GetMFCClassName()
	// GetMFCClassSchema()
	// GetTripletFeelType()
	// GetType()
	// HasTripletFeel()
	// IsAccelerando()
	// IsAlterationOfPace()
	// IsListesso()
	// IsMetronomeMarkerShown()
	// IsRitardando()
	// IsStandardMarker()
	// IsValidBeatsPerMinute($beatsPerMinute)
	// IsValidBeatType($beatType)
	// IsValidTripletFeelType($tripletFeelType)
	// IsValidType($type)
	// SetAlterationOfPace($accelerando)
	// SetBeatsPerMinute($beatsPerMinute)
	// SetBeatType($beatType)
	// SetDescription($description)
	// SetListessoBeatType($beatType)
	// SetTripletFeelType($tripletFeelType)
	// SetType($type)
?>
<?php
	 
	 
	class TempoMarker extends SystemSymbol {
		 
		 
		 
		const notShown = 0x00000000;
		const standardMarker = 0x00000001;
		const listesso = 0x00000002;
		const alterationOfPace = 0x00000003;
		 
		 
		 
		const half = 0x00000000;
		const halfDotted = 0x00000001;
		const quarter = 0x00000002;
		const quarterDotted = 0x00000003;
		const eighth = 0x00000004;
		const eighthDotted = 0x00000005;
		const sixteenth = 0x00000006;
		const sixteenDotted = 0x00000007;
		const thirtySecond = 0x00000008;
		const thirtySecondDotted = 0x00000009;
		 
		 
		 
		const noTripletFeel = 0x00000000;
		const tripletFeelEighth = 0x00000001;
		const tripletFeelSixteenth = 0x00000002;
		const tripletFeelEighthOff = 0x00000003;
		const tripletFeelSixteenthOff = 0x00000004;
		 
		 
		 
		const beatsPerMinuteMask = 0x0000ffff;
		const tripletFeelTypeMask = 0x00070000;
		const listessoBeatTypeMask = 0x00780000;
		const beatTypeMask = 0x07800000;
		const typeMask = 0x18000000;
		 
		// Default constants
		const DEFAULT_DESCRIPTION = "";
		const DEFAULT_BEAT_TYPE = self::quarter;
		const DEFAULT_BEATS_PER_MINUTE = 120;
		 
		// Beats Per Minute Constants
		const MIN_BEATS_PER_MINUTE = 40;
		const MAX_BEATS_PER_MINUTE = 300;
		 
		 
		// Member variables
		 
		protected $m_description = self::DEFAULT_DESCRIPTION;
		 
		 
		// MFC Class Functions
		 
		 
		function GetMFCClassName() {
			return "CTempoMarker";
		}
		 
		 
		function GetMFCClassSchema() {
			return 1;
		}
		 
		// Type Functions
		 
		 
		 
		function IsValidType($type) {
			return ($type <= self::alterationOfPace);
		}
		 
		 
		 
		function IsMetronomeMarkerShown() {
			return ($this->GetType() != self::notShown);
		}
		 
		// Standard Marker Functions
		 
		 
		function IsStandardMarker() {
			return ($this->GetType() == self::standardMarker);
		}
		 
		// Listesso Functions
		 
		 
		function IsListesso() {
			return ($this->GetType() == self::listesso);
		}
		 
		// Alteration Of Pace Functions
		 
		 
		function IsAlterationOfPace() {
			return ($this->GetType() == self::alterationOfPace);
		}
		 
		 
		function IsAccelerando() {
			return (($this->IsAlterationOfPace()) && ($this->GetBeatType() == 0));
		}
		 
		 
		function IsRitardando() {
			return (($this->IsAlterationOfPace()) && ($this->GetBeatType() == 1));
		}
		 
		// Beat Type Functions
		 
		 
		 
		function IsValidBeatType($beatType) {
			return ($beatType <= self::thirtySecondDotted);
		}
		 
		 
		// Triplet Feel Functions
		 
		 
		 
		function IsValidTripletFeelType($tripletFeelType) {
			return ($tripletFeelType <= self::tripletFeelSixteenthOff);
		}
		 
		function HasTripletFeel() {
			return ($this->GetTripletFeelType() != self::noTripletFeel);
		}
		 
		// Beats Per Minute Functions
		 
		 
		 
		function IsValidBeatsPerMinute($beatsPerMinute) {
			return (($beatsPerMinute >= self::MIN_BEATS_PER_MINUTE) && (($beatsPerMinute <= self::MAX_BEATS_PER_MINUTE)));
		}
		 
		 
		 
		 
		function GetBeatsPerMinute() {
			return (($this->m_data & self::beatsPerMinuteMask));
		}
		 
		// Description Functions
		 
		 
		 
		function SetDescription($description) {
			if (!$description != NULL) return 0;
			$this->m_description = $description;
			 return 1;
		}
		 
		 
		function GetDescription() {
			return ($this->m_description);
		}
		 
		 
		 
		 
		// Constructor/Destructor
		 
		 
		function TempoMarker($system=NULL, $position=NULL, $beatType=NULL, $beatsPerMinute=NULL, $description=NULL, $tripletFeelType=NULL) {
			 
			//------Last Checked------//
			// - Jan 13, 2005
			$this->SetType(self::standardMarker);
			$this->SetBeatType(self::DEFAULT_BEAT_TYPE);
			$this->SetBeatsPerMinute(self::DEFAULT_BEATS_PER_MINUTE);
			 
			 
			if (!$this->IsValidSystem($system)) return 0;
			if (!$this->IsValidPosition($position)) return 0;
			if (!$this->IsValidBeatType($beatType)) return 0;
			if (!$this->IsValidBeatsPerMinute($beatsPerMinute)) return 0;
			if (!$description != NULL) return 0;
			if (!$this->IsValidTripletFeelType($tripletFeelType)) return 0;
			 
			$this->SetSystem($system);
			$this->SetPosition($position);
			$this->SetStandardMarker($beatType, $beatsPerMinute, $description, $tripletFeelType);
		}
		 
		 
		function DoSerialize(&$stream){
		 
		
			parent::DoSerialize($stream);

			WRITE_CSTRING ($stream,$this->m_description);

			return 1;
		}
		 
		 
		 
		function DoDeserialize(&$stream){
		 
		
			parent::DoDeserialize($stream);
		 
			$this->m_description = READ_CSTRING ($stream);
		
		}
		 
		// Type Functions
		
		 
		 
		function SetType($type) {
			 
			
			if (!$this->IsValidType($type)) return 0;
			 
			$this->m_data &= ~self::typeMask;
			$this->m_data |= ($type << 27);
			 
			return 1;
		}
		 
		 
		 
		function GetType() {
			 
			//------Last Checked------//
			// - Jan 13, 2005
			return ((($this->m_data & self::typeMask) >> 27));
		}
		 
		 
		 
		 
		 
		 
		 
		function SetStandardMarker($beatType, $beatsPerMinute, $description, $tripletFeelType) {
			 
			//------Last Checked------//
			// - Jan 13, 2005
			if (!$this->IsValidBeatType($beatType)) return 0;
			if (!$this->IsValidBeatsPerMinute($beatsPerMinute)) return 0;
			if (!$description != NULL) return 0;
			if (!$this->IsValidTripletFeelType($tripletFeelType)) return 0;
			 
			$this->m_data = 0;
			$this->SetType(self::standardMarker);
			$this->SetBeatType($beatType);
			$this->SetBeatsPerMinute($beatsPerMinute);
			$this->SetDescription($description);
			$this->SetTripletFeelType($tripletFeelType);
			 
			return 1;
		}
		 
		 
		 
		 
		 
		 
		function SetListesso($beatType, $listessoBeatType, $description) {
			 
			//------Last Checked------//
			// - Jan 13, 2005
			if (!$this->IsValidBeatType($beatType)) return 0;
			if (!$this->IsValidBeatType($listessoBeatType)) return 0;
			if (!$description != NULL) return 0;
			 
			// Clear all current data
			$this->m_data = 0;
			 
			$this->SetType(self::listesso);
			$this->SetBeatType($beatType);
			$this->SetListessoBeatType($listessoBeatType);
			$this->SetDescription($description);
			 
			return 1;
		}
		 
		 
		 
		 
		function SetAlterationOfPace($accelerando) {
			 
			//------Last Checked------//
			// - Jan 13, 2005
			 
			// Clear all current data
			$this->m_data = 0;
			$this->m_description = '';
			 
			// Set the $type
			$this->SetType(self::alterationOfPace);
			 
			// Quirky stuff: accelerando uses beat $type 0, ritardando used beat $type 1
			if ($accelerando)
				$this->SetBeatType(0);
			else
				$this->SetBeatType(1);
			 
			return 1;
		}
		 
		// Beat Type Functions
		 
		 
		 
		function SetBeatType($beatType) {
			 
			//------Last Checked------//
			// - Jan 13, 2005
			if (!$this->IsValidBeatType($beatType)) return 0;
			 
			$this->m_data &= ~self::beatTypeMask;
			$this->m_data |= ($beatType << 23);
			 
			return 1;
		}
		 
		 
		 
		function GetBeatType() {
			 
			//------Last Checked------//
			// - Jan 13, 2005
			return ((($this->m_data & self::beatTypeMask) >> 23));
		}
		 
		// Listesso Beat Type Functions
		 
		 
		 
		function SetListessoBeatType($beatType) {
			 
			//------Last Checked------//
			// - Jan 13, 2005
			if (!$this->IsValidBeatType($beatType)) return 0;
			 
			$this->m_data &= ~self::listessoBeatTypeMask;
			$this->m_data |= ($beatType << 19);
			 
			return 1;
		}
		 
		 
		 
		function GetListessoBeatType() {
			 
			//------Last Checked------//
			// - Jan 13, 2005
			return ((($this->m_data & self::listessoBeatTypeMask) >> 19));
		}
		 
		// Triplet Feel Functions
		 
		 
		function SetTripletFeelType($tripletFeelType) {
			 
			//------Last Checked------//
			// - Jan 13, 2005
			if (!$this->IsValidTripletFeelType($tripletFeelType)) return 0;
			 
			$this->m_data &= ~self::tripletFeelTypeMask;
			$this->m_data |= ($tripletFeelType << 16);
			 
			return 1;
		}
		 
		 
		 
		function GetTripletFeelType() {
			 
			//------Last Checked------//
			// - Jan 13, 2005
			return (($this->m_data & self::tripletFeelTypeMask) >> 16);
		}
		 
		// Beats Per Minute Functions
		 
		 
		 
		function SetBeatsPerMinute($beatsPerMinute) {
			 
			//------Last Checked------//
			// - Jan 13, 2005
			if (!$this->IsValidBeatsPerMinute($beatsPerMinute)) return 0;
			 
			$this->m_data &= ~self::beatsPerMinuteMask;
			$this->m_data |= $beatsPerMinute;
			 
			return 1;
		}
		 
	}
?>

